//***********************************************************************************//
//HJMedia FRAMEWORK SOURCE;
//AUTHOR:
//CREATE TIME:
//***********************************************************************************//
#pragma once

#if defined(__ANDROID__)
#   include <sys/cdefs.h>
#elif defined(__APPLE__)
#   include <TargetConditionals.h>
#elif defined(__linux__)
#   include <features.h>
#endif

//***********************************************************************************//
/*******
*****Operating System Macro******************************************
* WSYS(WINDOWS), USYS(LINUX, UNIX), OSYS(APPLE), MSYS(MAC), ISYS(IOS), ASYS(ANDROID), FSYS(HJ_OS_FREEBSD), ESYS(EMSCRIPTEN)
* HJ_OS_WINDOWS, HJ_OS_LINUX(LINUX, UNIX), HJ_OS_UNIX, HJ_OS_APPLE, HJ_OS_MACOS(MAC OS X), HJ_OS_IOS, HJ_OS_ANDROID, HJ_OS_HARMONY, HJ_OS_FREEBSD, HJ_OS_OPENBSD, HJ_OS_BEOS, HJ_OS_SUNOS
*****System Arch OS BITE Macro*************************************
* HJ_ARCH_OS32, HJ_ARCH_OS64
*****CPU Type Macro******************************************
* HJ_ARCH_X86         : HJ_ARCH_X86_32, HJ_ARCH_X86_64
* HJ_ARCH_ARM        : HJ_ARCH_ARM_32, HJ_ARCH_ARM_64
* HJ_ARCH_MIPS      :
* HJ_ARCH_PPC        :
* HJ_ARCH_ALPHA    :
* HJ_ARCH_BFIN        :
* HJ_ARCH_SH4        :
* HJ_ARCH_SPRAC     :                //(VIS ultraSprac)
* HJ_ARCH_AVR        :
* HJ_ARCH_M68K        :
* HJ_ARCH_PARISC    :
* HJ_ARCH_TILEGX    :
* HJ_ARCH_TILEPRO    :
* HJ_ARCH_TOMI        :
*****HW Macro************************************************
* HJ_HAVE_GPU

* HJ_HAVE_HW_ACCELS                    //HARDWORD ACCELETRAION
* HJ_HAVE_CUDA
* HJ_HAVE_OPENCL
*****Assembly Macro************************************************
* HJ_HAVE_ASM
* HJ_HAVE_INLINE_ASM
*****Character Set Macro************************************************
* HJ_UNICODE, HJ_MUTIBYTE, HJ_UTF8
******/
/*
   The operating system, must be one of: (HJ_OS_x)

     DARWIN   - Any Darwin system (macOS, iOS, watchOS, tvOS)
     MACOS    - macOS
     IOS      - iOS
     WATCHOS  - watchOS
     TVOS     - tvOS
     WIN32    - Win32 (Windows 2000/XP/Vista/7 and Windows Server 2003/2008)
     CYGWIN   - Cygwin
     SOLARIS  - Sun Solaris
     HPUX     - HP-UX
     LINUX    - Linux [has variants]
     FREEBSD  - FreeBSD [has variants]
     NETBSD   - NetBSD
     OPENBSD  - OpenBSD
     INTERIX  - Interix
     AIX      - AIX
     HURD     - GNU Hurd
     QNX      - QNX [has variants]
     QNX6     - QNX RTP 6.1
     LYNX     - LynxOS
     BSD4     - Any BSD 4.4 system
     UNIX     - Any UNIX BSD/SYSV system
     ANDROID  - Android platform
     HAIKU    - Haiku
     WEBOS    - LG WebOS

   The following operating systems have variants:
     LINUX    - both HJ_OS_LINUX and HJ_OS_ANDROID are defined when building for Android
              - only HJ_OS_LINUX is defined if building for other Linux systems
     MACOS    - both HJ_OS_BSD4 and HJ_OS_IOS are defined when building for iOS
              - both HJ_OS_BSD4 and HJ_OS_MACOS are defined when building for macOS
     FREEBSD  - HJ_OS_FREEBSD is defined only when building for FreeBSD with a BSD userland
              - HJ_OS_FREEBSD_KERNEL is always defined on FreeBSD, even if the userland is from GNU
*/

#if defined(__APPLE__) && (defined(__GNUC__) || defined(__xlC__) || defined(__xlc__))
#  include <TargetConditionals.h>
#  if defined(TARGET_OS_MAC) && TARGET_OS_MAC
#    define HJ_OS_DARWIN
#    define HJ_OS_BSD4
#    ifdef __LP64__
#      define HJ_OS_DARWIN64
#    else
#      define HJ_OS_DARWIN32
#    endif
#    if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
#      define HJ_PLATFORM_UIKIT
#      if defined(TARGET_OS_WATCH) && TARGET_OS_WATCH
#        define HJ_OS_WATCHOS
#      elif defined(TARGET_OS_TV) && TARGET_OS_TV
#        define HJ_OS_TVOS
#      else
#        // TARGET_OS_IOS is only available in newer SDKs,
#        // so assume any other iOS-based platform is iOS for now
#        define HJ_OS_IOS
#      endif
#    else
#      // TARGET_OS_OSX is only available in newer SDKs,
#      // so assume any non iOS-based platform is macOS for now
#      define HJ_OS_MACOS
#    endif
#  else
#    error "not been ported to this Apple platform
#  endif
#elif defined(__WEBOS__)
#  define HJ_OS_WEBOS
#  define HJ_OS_LINUX
#elif defined(__ANDROID__) || defined(ANDROID)
#  define HJ_OS_ANDROID
#  define HJ_OS_LINUX
#elif defined(__OHOS__)
#  define HJ_OS_HARMONY
#  define HJ_OS_LINUX
#elif defined(__CYGWIN__)
#  define HJ_OS_CYGWIN
#elif !defined(SAG_COM) && (!defined(WINAPI_FAMILY) || WINAPI_FAMILY==WINAPI_FAMILY_DESKTOP_APP) && (defined(WIN64) || defined(_WIN64) || defined(__WIN64__))
#  define HJ_OS_WIN32
#  define HJ_OS_WIN64
#elif !defined(SAG_COM) && (defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__))
#    define HJ_OS_WIN32
#elif defined(__sun) || defined(sun)
#  define HJ_OS_SOLARIS
#elif defined(hpux) || defined(__hpux)
#  define HJ_OS_HPUX
#elif defined(__native_client__)
#  define HJ_OS_NACL
#elif defined(__EMSCRIPTEN__)
#  define HJ_OS_WASM
#elif defined(__linux__) || defined(__linux)
#  define HJ_OS_LINUX
#elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
#  ifndef __FreeBSD_kernel__
#    define HJ_OS_FREEBSD
#  endif
#  define HJ_OS_FREEBSD_KERNEL
#  define HJ_OS_BSD4
#elif defined(__NetBSD__)
#  define HJ_OS_NETBSD
#  define HJ_OS_BSD4
#elif defined(__OpenBSD__)
#  define HJ_OS_OPENBSD
#  define HJ_OS_BSD4
#elif defined(__INTERIX)
#  define HJ_OS_INTERIX
#  define HJ_OS_BSD4
#elif defined(_AIX)
#  define HJ_OS_AIX
#elif defined(__Lynx__)
#  define HJ_OS_LYNX
#elif defined(__GNU__)
#  define HJ_OS_HURD
#elif defined(__QNXNTO__)
#  define HJ_OS_QNX
#elif defined(__INTEGRITY)
#  define HJ_OS_INTEGRITY
#elif defined(__rtems__)
#  define HJ_OS_RTEMS
#elif defined(VXWORKS) /* there is no "real" VxWorks define - this has to be set in the mkspec! */
#  define HJ_OS_VXWORKS
#elif defined(__HAIKU__)
#  define HJ_OS_HAIKU
#elif defined(__MAKEDEPEND__)
#else
#  error "has not been ported to this OS"
#endif

#if defined(HJ_OS_WIN32) || defined(HJ_OS_WIN64)
#  define HJ_OS_WINDOWS
#  define HJ_OS_WIN
// On Windows, pointers to dllimport'ed variables are not constant expressions,
// so to keep to certain initializations (like QMetaObject) constexpr, we need
// to use functions instead.
#  define HJ_NO_DATA_RELOCATION
#endif

#if defined(HJ_OS_WIN)
#  undef HJ_OS_UNIX
#elif !defined(HJ_OS_UNIX)
#  define HJ_OS_UNIX
#endif

// Compatibility synonyms
#ifdef HJ_OS_DARWIN
#define HJ_OS_MAC
#endif
#ifdef HJ_OS_DARWIN32
#define HJ_OS_MAC32
#endif
#ifdef HJ_OS_DARWIN64
#define HJ_OS_MAC64
#endif
#ifdef HJ_OS_MACOS
#define HJ_OS_MACX
#define HJ_OS_OSX
#endif

#ifdef HJ_OS_DARWIN
#  include <Availability.h>
#  include <AvailabilityMacros.h>
#
#  ifdef HJ_OS_MACOS
#    if !defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_6
#       undef __MAC_OS_X_VERSION_MIN_REQUIRED
#       define __MAC_OS_X_VERSION_MIN_REQUIRED __MAC_10_6
#    endif
#    if !defined(MAC_OS_X_VERSION_MIN_REQUIRED) || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6
#       undef MAC_OS_X_VERSION_MIN_REQUIRED
#       define MAC_OS_X_VERSION_MIN_REQUIRED MAC_OS_X_VERSION_10_6
#    endif
#  endif
#
#  // Numerical checks are preferred to named checks, but to be safe
#
#  if !defined(__MAC_10_11)
#       define __MAC_10_11 101100
#  endif
#  if !defined(__MAC_10_12)
#       define __MAC_10_12 101200
#  endif
#  if !defined(__MAC_10_13)
#       define __MAC_10_13 101300
#  endif
#  if !defined(__MAC_10_14)
#       define __MAC_10_14 101400
#  endif
#  if !defined(__MAC_10_15)
#       define __MAC_10_15 101500
#  endif
#  if !defined(__MAC_10_16)
#       define __MAC_10_16 101600
#  endif
#  if !defined(MAC_OS_X_VERSION_10_11)
#       define MAC_OS_X_VERSION_10_11 __MAC_10_11
#  endif
#  if !defined(MAC_OS_X_VERSION_10_12)
#       define MAC_OS_X_VERSION_10_12 __MAC_10_12
#  endif
#  if !defined(MAC_OS_X_VERSION_10_13)
#       define MAC_OS_X_VERSION_10_13 __MAC_10_13
#  endif
#  if !defined(MAC_OS_X_VERSION_10_14)
#       define MAC_OS_X_VERSION_10_14 __MAC_10_14
#  endif
#  if !defined(MAC_OS_X_VERSION_10_15)
#       define MAC_OS_X_VERSION_10_15 __MAC_10_15
#  endif
#  if !defined(MAC_OS_X_VERSION_10_16)
#       define MAC_OS_X_VERSION_10_16 __MAC_10_16
#  endif
#
#  if !defined(__IPHONE_10_0)
#       define __IPHONE_10_0 100000
#  endif
#  if !defined(__IPHONE_10_1)
#       define __IPHONE_10_1 100100
#  endif
#  if !defined(__IPHONE_10_2)
#       define __IPHONE_10_2 100200
#  endif
#  if !defined(__IPHONE_10_3)
#       define __IPHONE_10_3 100300
#  endif
#  if !defined(__IPHONE_11_0)
#       define __IPHONE_11_0 110000
#  endif
#  if !defined(__IPHONE_12_0)
#       define __IPHONE_12_0 120000
#  endif
#endif

#if defined(__arm__) || defined(_M_ARM)
#define HJ_ARM32
#endif
#if defined(__arm64) || defined(__arm64__) || defined(__aarch64__) || defined(_M_ARM64)
#define HJ_ARM64
#endif

#if defined(__x86_64__) || defined(_M_X64)
#define HJ_X64
#elif defined(__i386) || defined(_M_IX86)
#define HJ_X86
#elif defined(MA_ARM32) || defined(MA_ARM64)
#define MA_ARM
#endif
